<template>
  <view>
    <view class="add-btn" @click="render.setUniData(mData)">
      提交
    </view>
    <view class="content-layout">
      <view class="title">mData</view>
      <view>name:{{ mData.name }}</view>
      <view>age:{{ mData.age }}</view>
    </view>
    <view class="content-layout">
      <view class="title">renderData</view>
      <view>key:{{ renderData.key }}</view>
      <view>number:{{ renderData.number }}</view>
    </view>
  </view>
</template>

<script>
export default {
  name: "render",
  data() {
    return {
      mData: {name: '4444', age: '555'},
      renderData: {key: '', number: ''}
    }
  },
  methods: {
    setBackData(data){

    },
    setRenderData(data) {
      this.renderData = data
    },
  }
}
</script>

<script module="render" lang="renderjs">
export default {
  data() {
    return {
      messageData: {name: '222', age: 333}
    }
  },
  mounted() {
    this.connectSee()
  },
  methods: {
    connectSee() {
      console.log("mounted======")
      if (window.EventSource) {
        let chat = {sex: '1', nickName: '18810126510', fromUserName: '11'}
        let url = `http://yxchat.impc.com.cn/vuechat/getConnection?channel=A&sex=${chat.sex}&nickName=${chat.nickName}&fromUserName=${chat.fromUserName}`
        const se = new EventSource(url)
        console.log('EventSource', se)
        console.log('EventSource', url)
        se.addEventListener('open', function (e) {
          console.log('EventSource', '连接打开')
        })
        se.addEventListener('message', function (e) {
          console.log("EventSource,message", e)
        })
        se.addEventListener('error', function (e) {
          console.log('连接断掉了')
          se.close();
        })
      }
    },
    setUniData(data,) {
      console.log("setUniData1",data)
      console.log("setUniData2",this.messageData)
      this.messageData = data
      console.log("setUniData3",this.messageData)
      //this.$ownerInstance.callMethod('receiveRenderData', this.messageData)
      this.$ownerInstance.callMethod('setRenderData', {key:'111',number:'222'})
    }
  }
}




</script>

<style scoped>
.add-btn {
  margin: 20px;
  text-align: center;
  background: gray;
  padding: 5px 10px;
  border-radius: 5px;
}

.content-layout {
  margin: 20px;
  padding: 20px;
  border: 1px solid #eaeaea;
}

.title {
  color: red;
}
</style>
